// pages/myshop/myshop.ts
import {createStoreBindings} from "mobx-miniprogram-bindings"
import {store} from "../../store/store"
import axios from "../../utils/axios"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shopdetail:[],
    goodstatus:['满货','缺货'],
    shopstatus:['休息中','营业中'],
  },
  async getmyshop(){
    var token=getApp().globalData.accessToken
    var result=await axios.get('/shop?flag=1&pass=1')
    console.log(result)
    var myshops=result.content
    var shopdetails=[]
    for (let i = 0; i < myshops.length; i++) {
      const myshop = myshops[i];
      var shopdetail={
        title:myshop[4],
        id:myshop[0],
        userId:myshop[1],
        school:myshop[2],
        region:myshop[3],
        score:myshop[5],
        type:myshop[6],
        status:myshop[8],
        location:myshop[9]
      }
    shopdetail.condition=myshop[7].split(",")
    }
    shopdetails.push(shopdetail)
    this.setData({
      shopdetail:shopdetails
    })
    console.log(this.data.shopdetail)
  },
  creatshop:function(){
    wx.navigateTo({
      url:"../creatshop/creatshop"
    })
  },
  changestatus(e){
    var index=e.currentTarget.dataset.index
    var status=JSON.parse(e.detail.value)
    var id=this.data.shopdetail[index].id
    var key='shopdetail['+index+'].status'
    this.setData({
      [key]:status
    })
    console.log(this.data.shopdetail[index])
    var token=getApp().globalData.accessToken
    axios.patch("/shop/status?+shopId="+id+"&status="+status,{})
  },
  changegoodstatus(e){
    var index=e.currentTarget.dataset.index
    var status=JSON.parse(e.detail.value)
    var key='shopdetail['+index+'].goodstatus'
    this.setData({
      [key]:status
    })
    console.log(this.data.shopdetail[index])
    var token=getApp().globalData.accessToken
  },
  shopdetail:function(e){
    var index=e.currentTarget.dataset.index
    console.log(index)
    wx.navigateTo({
      url:"../shopdetail/shopdetail?shopdetail="+JSON.stringify(this.data.shopdetail[index])
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad() {
    this.getmyshop()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})